package sg.techstudio.suntec.dao;

import java.util.List;

import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import sg.techstudio.suntec.object.RoleObj;

@Repository("roleDao")
@Transactional
public class RoleDao {
	private static final Log log = LogFactory.getLog(RoleDao.class);

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	public List<RoleObj> getAllRoles(){
		log.debug("getAllRoles() entry");
		Criteria c = sessionFactory.getCurrentSession().createCriteria(RoleObj.class);
		return c.list();
	}
	
	public RoleObj getRole(String id) {
		log.debug("getRole(String) entry");
		return getRole(NumberUtils.toLong(id));
	}
	
	public RoleObj getRole(Long id) {
		log.debug("getRole(Long) entry");
		return (RoleObj) sessionFactory.getCurrentSession().get(RoleObj.class, id);
	}
}
